package com.zdsoft.crm.dao.auth;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.zdsoft.crm.entity.auth.SysRole;
/**
 * 角色管理
 * @author Administrator
 *
 */
public interface ISysRoleMapper {

	@Insert("insert into sys_role(id,role_name,role_info) values(#{id},#{role_name,jdbcType=VARCHAR},#{role_info,jdbcType=VARCHAR})")
	int save(SysRole sysRole);

	@Delete("delete from sys_role where id = #{id}")
	public int deleteById(String id);
	
	@Select("select role_name,role_info from sys_role where id=#{id}")
	SysRole findById(String id);

	/*@Select("select id,role_name,role_info from sys_role limit #{startIndex},#{pageSize}")
	List<SysRole> pageList(@Param("startIndex") Integer startIndex, @Param("pageSize") Integer pageSize);
	*/
	@Select("SELECT * FROM("
			+ "SELECT A.*,ROWNUM RN "
			+ "FROM "
			+ " (SELECT * FROM SYS_ROLE ) A"
			+ " WHERE ROWNUM<=#{endIndex})  TL "
			+ " WHERE RN > #{startIndex}")
	List<SysRole> pageList(@Param("startIndex") Integer startIndex, @Param("endIndex") Integer endIndex);
	
	@Select("SELECT count(id) FROM sys_role")
	Long totalCount();

	@Update("update sys_role set role_name=#{role_name,jdbcType=VARCHAR},role_info=#{role_info,jdbcType=VARCHAR} where id=#{id}")
	int update(SysRole sysRole);
	
	@Select("select * from sys_role")
	List<SysRole> select();
	
	@Select("select r.* from sys_role r"
			+ " inner join sys_user_role sur on sur.role_id = r.id"
			+ " inner join sys_user su on su.id = sur.user_id"
			+ " where su.suername = #{userId}")
	SysRole findByUserId(String userId);
	
}
